package com.cjx.stars.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;


/**
 * @author cjx
 */
@Configuration // 配置类
@EnableSwagger2WebMvc // 开启 swagger2 的自动配置
public class SwaggerConfig {

    /**
     * 创建一个 swagger 的 bean 实例
     * @return
     */
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select() // 设置扫描接口
                .apis(RequestHandlerSelectors
                      .basePackage("com.cjx.stars.controllerr") // 扫描指定包下的接口，最为常用
                )
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Swagger 测试文档")
                .description("测试文档")
                .termsOfServiceUrl("https://xxx.com")
                .contact("xxx")
                .version("1.0")
                .build();
    }


}
